//
//  LoginoutView.m
//  location
//
//  Created by Dongxiang Xu on 2025/6/9.
//

#import "LoginoutView.h"

@implementation LoginoutView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.masksToBounds = YES;
        [self initView];
    }
    return self;
}

- (void)initView
{
    UIView *infoView = [[UIView alloc] initWithFrame:CGRectMake(12, SCREEN_HEIGHT, SCREEN_WIDTH-24, 180)];
    infoView.layer.masksToBounds = YES;
    [infoView.layer setCornerRadius:26];
    infoView.backgroundColor = RealWhiteColor;
    [self addSubview:infoView];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, infoView.width, 28)];
    title.textAlignment = NSTextAlignmentCenter;
    title.text = @"确定要退出登录吗？";
    title.textColor = BlackColor;
    title.font = MEDIUM_FONT(20);
    [infoView addSubview:title];
        
    
    NSArray *array = @[@"取消",@"退出登录"];
    for (int i = 0; i < array.count; i ++) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(32+i*((infoView.width-80)/2+22), CGRectGetMaxY(title.frame)+28, (infoView.width-80)/2, 54)];
        button.layer.masksToBounds = YES;
        [button.layer setCornerRadius:27];
        [button setTitle:array[i] forState:UIControlStateNormal];
        [button.titleLabel setFont:MEDIUM_FONT(17)];
        if (i==0) {
            button.backgroundColor = LightBGColor;
            [button setTitleColor:RealBlackColor forState:UIControlStateNormal];
        }else{
            button.backgroundColor = RedColor;
            [button setTitleColor:RealWhiteColor forState:UIControlStateNormal];
        }
        [[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            [UIView animateWithDuration:0.3 animations:^{
                infoView.y = SCREEN_HEIGHT;
                self.backgroundColor = [RealBlackColor colorWithAlphaComponent:0];
            } completion:^(BOOL finished) {
                [self removeFromSuperview];
                if (i==1) {
                    self.LoginoutBlock();
                }
            }];
        }];
        [infoView addSubview:button];
    }
    
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [self insertSubview:bgView atIndex:0];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
    [[tap rac_gestureSignal] subscribeNext:^(id x) {
        [UIView animateWithDuration:0.3 animations:^{
            infoView.y = SCREEN_HEIGHT;
            self.backgroundColor = [RealBlackColor colorWithAlphaComponent:0];
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];
    }];
    [bgView addGestureRecognizer:tap];
    
    [UIView animateWithDuration:0.3 animations:^{
        infoView.y = SCREEN_HEIGHT-212;
        self.backgroundColor = [RealBlackColor colorWithAlphaComponent:0.4];
    }];
}

@end
